/**
 * Project Name:mauto-web
 * File Name:ApiEnterpriseController.java
 * Package Name:com.inftech.mauto.sys.web.front
 * Date:2016年10月17日下午9:51:38
 * Copyright (c) 2016, inf-technology Co., Ltd. All Rights Reserved.
 *
*/

package com.inftech.mauto.core.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.inftech.mauto.common.base.BaseController;
import com.inftech.mauto.common.base.BusinessException;
import com.inftech.mauto.core.entity.Comment;
import com.inftech.mauto.core.service.CommentService;
import com.mingsoft.util.StringUtil;

import net.mingsoft.basic.util.BasicUtil;

/**
 * ClassName:CommentController <br/>
 * Function: 评价后台. <br/>
 * Date: 2016年10月17日 下午9:51:38 <br/>
 * 
 * @author puyf
 * @version
 * @since JDK 1.7
 */
@Controller
@RequestMapping("/${managerPath}/comment")
public class CommentController extends BaseController {

	/**
	 * 注入评价业务层
	 */
	@Autowired
	protected CommentService commentService;

	/**
	 * 
	 * list:获取评价列表. <br/>
	 *
	 * @author puyf
	 * @param request
	 * @since JDK 1.7
	 */
	@RequestMapping(value = "/list")
	public String list(HttpServletRequest request) throws Exception {
		try {
			BasicUtil.startPage();
			Map<String, Object> whereMap = BasicUtil.assemblyRequestMap();
			Object commentTime = whereMap.get("commentTime");
			if (!StringUtil.isBlank(commentTime)) {
				whereMap.put("commentTimeBegin", commentTime.toString().split("至")[0]);
				whereMap.put("commentTimeEnd", commentTime.toString().split("至")[1]);
			}
			// 获取评价列表
			List<Comment> commentList = commentService.queryCommentList(whereMap);
			BasicUtil.endPage(commentList);
			request.setAttribute("commentList", commentList);
			LOG.info("后台获取评价列表成功");
		} catch (Exception e) {
			if (e instanceof BusinessException) {
				throw e;
			}
			LOG.error("后台获取评价列表失败", e);
		}
		return view("/mauto/core/comment_list");
	}
}
